﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Controller;
using buildingLib.fee;
using DocPrinter;

namespace _dmis.fee
{
    public partial class InvoiceTicketCloseDlg : _dmis.UIFormBase, ICommand
    {
        InvoiceTaskList taskList;
        InvoiceTicket m_ticket;
        #region ICommand
        public static string MenuItemName()
        {
            return "缴费审核";
        }
        public static Image MenuItemImage()
        {
            return _dmis.Properties.Resources.order.ToBitmap();
        }
        public static void MF_DoExcecute()
        {
            InvoiceTicketCloseDlg dlg = new InvoiceTicketCloseDlg();
            dlg.ShowDialog();
        }

        public static void MF_DoUpdateUI(ToolStripItem tsItem)
        {
            tsItem.Enabled = true;
        }
        #endregion
        public InvoiceTicketCloseDlg()
        {
            InitializeComponent();
        }

        private void InvoiceTicketCloseDlg_Load(object sender, EventArgs e)
        {
            DoorSelect dlg = new DoorSelect();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.Text = dlg.DoorName + "缴费信息";
                //查询信息 
                taskList = InvoiceTaskList.GetInvoiceItems(" [invoice].doorID='" + dlg.DoorID + "' and [invoice_task].status=2 and ");
                invoiceTicketBindingSource.DataSource = taskList;
            }
            else
                this.Close();
        }

        private void InvoiceTicketCloseDlg_Shown(object sender, EventArgs e)
        {
            
        }

        private void dgvTicket_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex != 0)
                return;
            
            m_ticket = (InvoiceTicket)invoiceTicketBindingSource.Current;

            Image ticketImg = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
            Graphics g = Graphics.FromImage(ticketImg);
            g.ScaleTransform(0.8f, 0.8f);

            FeePrinter.PrintInovice(g, m_ticket);

            this.pictureBox1.Image = ticketImg;
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            ((InvoiceTicket)invoiceTicketBindingSource.Current).CloseTicket();
            this.Close();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
        }

    }
}